<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <script type="text/javascript" src="../../inc/ctx.jsp"></script>
        <script type="text/javascript" src="../js/g.js"></script>
        <link rel="stylesheet" href="../../ked/js/themes/default/default.css" />
        <link rel="stylesheet" href="../../ked/js/plugins/code/prettify.css" />
        <script charset="utf-8" src="../../ked/js/kindeditor-min.js"></script>
        <script charset="utf-8" src="../../ked/js/zh_CN.js"></script>
        <link href="../css/com.css" type="text/css" rel="stylesheet"/>
        <style>
            img.s1{width:100px;border:1px #EFEFEF solid;padding:1px;}
            #panel{width:95%;}
            #pageContent{width:98%; background:#FFF; border:1px solid #039; height:300px;font-size:13px;padding:3px;line-height:24px;font-family:Verdana, Geneva, sans-serif;}
        </style>
    </head>
    <body>

        <div id="panel">
            <form id="frm" name="frm">
                <table>
                    <tr>
                        <th colspan="5">Edm邮件发送</th>
                    </tr>
                    <tr>
                      <td height="31" class="r">Edm邮件名称：</td>
                      <td colspan="2"><label for="name"></label>
                      <input name="name" type="text" id="name" size="80" maxlength="100"></td>
                      <td>&nbsp;</td>
                      <td>edm邮件名称，用于收到邮件在列表中显示</td>
                    </tr>
                    <tr>
                        <td height="31" class="r">邮箱列表：</td>
                        <td colspan="2">&nbsp;</td>
                        <td width="8%">&nbsp;</td>
                        <td>每行一个邮箱地址</td>
                    </tr>
                    <tr>
                        <td height="31" class="r">&nbsp;</td>
                        <td colspan="4"><label for="mailList"></label>
                            <textarea name="mailList" id="mailList" cols="80" rows="10"></textarea></td>
                    </tr>
                    <tr>
                      <td height="26" class="r">邮件主题：</td>
                      <td colspan="2"><label for="subject"></label>
                      <input name="subject" type="text" id="subject" size="80" maxlength="100"></td>
                      <td>&nbsp;</td>
                      <td>邮件主题</td>
                    </tr>
                    <tr>
                        <td height="26" class="r">邮件内容：</td>
                        <td colspan="2">&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <td height="26" class="r">&nbsp;</td>
                        <td colspan="4"><textarea name="content" id="content" cols="120" rows="20"></textarea></td>
                    </tr>
                    <tr>
                        <td width="14%" align="right">&nbsp;</td>
                        <td width="1%">&nbsp;</td>
                        <td colspan="2" class="c"><input name="submitBtn" type="button" class="button medium orange" id="submitBtn" tabindex="7" value="发送邮件" />      </td>
                        <td width="25%">&nbsp;</td>
                    </tr>
                </table>
            </form>
        </div>



        <script type="text/javascript">
            // 初始化编辑器
            var contentEditor ; 
            KindEditor.ready(function(K) {
                contentEditor = K.create('#content', {
                    uploadJson : KindUpload.UploadUrl,
                    fileManagerJson : KindUpload.fileMgrUrl,
                    allowFileManager : true,
                    afterCreate : function() {
                        var self = this;
                        self.sync();
                    }
                });
            });
            
            // 清理空格和回车符
            function clearWhiteChar(s){
                var html = s || '';
                var pageHtml = html.replace(/[\s]{3}/g," ").replace(/[\s]{2}/g," ").replace(/>\s</g,"><")
                .replace(/[\f\t\b\n\r]{1,}/g,"");
                return pageHtml;
            };
            
            function formatMailList(s){
                return $.trim(s).replace(/[\f\t\b\r]{1,}/g,"").replace(/[\n]{1,}/g,',').replace(/\s/g,"");
            };
            
            function sendMail(){
                if(!window.confirm("确定发送邮件吗?"))return;
                contentEditor.sync();
                var p = {
                    name:$.trim($('#name').val()),
                    subject:$.trim($('#subject').val()),
                    mailList:formatMailList($('#mailList').val()),
                    content:clearWhiteChar($('#content').val())
                };
                var n = p.mailList.split(',').length;
                if(p.name.length<2 || p.name.length>100){
                    ut.m('邮件名称字符请控制在2-100个字内');
                    return;
                }
                if(p.subject.length<2 || p.subject.length>100){
                    ut.m('邮件主题字符请控制在2-100个字内');
                    return;
                }
                if(n<1 || n>1000){
                    ut.m('邮件地址必须在1-1000个内，请检查后再操作。');
                    return;
                }
                if(p.content.replace(/<[.[^<]]*>/g,'').length<9){
                    ut.m('邮件内容字数过少.');
                    return;
                }
                TxBox.wait('正在发送EDM...请勿关闭浏览器');
                $('#submitBtn').attr('disabled','disabled');
                $.post('../app/mailer/send_edm.shtm',$.param(p),function(x){
                    ut.m(x);
                    $('#submitBtn').removeAttr('disabled');
                    TxBox.hide();
                });
            };
            
            $('#submitBtn').bind('click',function(){
                sendMail();
            });
        </script>
    </body>
</html>